package net.pulseproject.router.systemtest;

import javax.swing.JButton;
import javax.swing.JTextArea;

import net.pulseproject.router.app.view.MainWindow;
import net.pulseproject.router.app.view.MainWindowImpl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.objogate.wl.swing.AWTEventQueueProber;
import com.objogate.wl.swing.driver.ComponentDriver;
import com.objogate.wl.swing.driver.JButtonDriver;
import com.objogate.wl.swing.driver.JFrameDriver;
import com.objogate.wl.swing.driver.JTextComponentDriver;
import com.objogate.wl.swing.gesture.GesturePerformer;

@SuppressWarnings("unchecked")
public class JavaAppMainWindowDriver extends JFrameDriver {
	
	private static final Log LOG = LogFactory.getLog(JavaAppMainWindowDriver.class);
	
    public JavaAppMainWindowDriver() {
        super(new GesturePerformer(), new AWTEventQueueProber(), ComponentDriver.named(MainWindow.NAME),
        		ComponentDriver.showingOnScreen());
    }
    
    public final void enterConfigurationText(final String config) {
    	this.configTextArea().replaceAllText(config);
    }
    
	public final void clickActivateRoutingButton() {
		LOG.debug("clickActivateRoutingButton()");
		this.button(MainWindowImpl.NAME_ACTIVATE_ROUTING_BUTTON).click();
	}

	public final void clickCloseRoutingButton() {
		LOG.debug("clickCloseRoutingButton()");
		this.button(MainWindowImpl.NAME_CLOSE_ROUTING_BUTTON).click();
	}
	
	private JButtonDriver button(final String name) {
        return new JButtonDriver(this, JButton.class, ComponentDriver.named(name));
    }
	
	private JTextComponentDriver configTextArea() {
        return new JTextComponentDriver<JTextArea>(this, JTextArea.class,
        		ComponentDriver.named(MainWindowImpl.NAME_CONFIGURATION_TEXT));
    }
	
}
